/**
 * 面试编程题 写一个函数
 * dog.__proto__ -> == b.prototype b是a的原型对象
 * dog.__proto__.__proto__.__proto__ ->null b是a的原型链上对象
 * @func instanceof   实现
 * @param a 实例对象 b 对象
 * @return boolean
 */
function Cat() {

}

function Dog() {

}
Dog.prototype.sayHi = function() {

}
const dog = new Dog();

function myInstanceof(a, b) {
    let proto = Object.getPrototypeOf(a); //api 拿到原型对象
    let prototype = b.prototype;
    // console.log(proto == b.prototype);
    while (true) {
        if (!proto) { return false }
        if (proto == prototype) return true;
        console.log(proto);
        proto = Object.getPrototypeOf(proto); //null
        console.log(proto);
    }
}
console.log(myInstanceof(dog, Dog)); //true
console.log(myInstanceof(dog, Object)); //true
console.log(myInstanceof(dog, Cat));